﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public static class Kho_DB
    {        
        public static DataTable SelectKho()
        {
                using (SqlConnection con = Connection.GetConnection())
                {
                    SqlDataAdapter da = new SqlDataAdapter("spSelectAllKho", con);
                    con.Open();
                    SqlCommand command = new SqlCommand("spSelectAllKho", con);
                    command.CommandType = CommandType.StoredProcedure;
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    return dt;
                }
        }

        public static void InsertKho(Kho newKho)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemKho",con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemKho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaKho", newKho.MaKho);
                command.Parameters.AddWithValue("@TenKho", newKho.TenKho);
                command.Parameters.AddWithValue("@DiaChiKho", newKho.DiaChi);
                command.ExecuteNonQuery();

            }
        }
        public static void UpdateKho(string oldMakho, Kho newKho)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatKho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapNhatKho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaKho", oldMakho);
                command.Parameters.AddWithValue("@TenKho", newKho.TenKho);
                command.Parameters.AddWithValue("@DiaChiKho", newKho.DiaChi);
                command.ExecuteNonQuery();

            }
        }
        public static void DeleteKho(string makho)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaKho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaKho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaKho", makho);
                command.ExecuteNonQuery();

            }
        }
    }
}
